<!--
 * @Descripttion:
 * @version:
 * @Author: zhuzm@linkstec.com
 * @Date: 2023-01-31 13:28:55
 * @LastEditors: sueRimn
 * @LastEditTime: 2023-03-30 16:41:03
-->
<template>
  <div class="search-list-product">
    <div class="list-item" v-for="(item, index) in dataFilter" :key="index">
      <div class="tags">
        <el-tag>{{ item.typeName }}</el-tag>
      </div>
      <!-- 每个类型中取前一个 -->
      <h2 class="name" v-html="item.list[0].title_v" @click="goDetail(item)"></h2>
    </div>
  </div>
</template>
<script>
import { verifyRoles } from '@/utils/verify';
export default {
  props: {
    data: {
      type: Array,
      default: () => {
        return [];
      }
    },
    max: {
      type: Number,
      default: Infinity
    }
  },
  computed: {
    dataFilter () {
      if (this.max === Infinity) return this.data;
      return this.data.slice(0, this.max).filter(item => item.list.length > 0);
    }
  },
  methods: {
    goDetail (item) {
      const id = item.list[0].id || item.list[0].reportId;
      switch (item.typeName) {
        case '研报':case '个股':case '图表':
          const judge = verifyRoles('GTJA', 0);
          if (!judge) {
            return;
          }
          if (item.reportType == 'xst') {
            window.location.href = process.env.VUE_APP_SERVICE_CP_NEWPREPORTDETAILS + '\\' + id;
          } else {
            window.location.href = process.env.VUE_APP_SERVICE_CP_PREPORTDETAILS + '\\' + id;
          }
        break;
        case '活动':
          if (id === '16902') {
            window.location.href = process.env.VUE_APP_SERVICE_CP_HOMEACTIVITY;
            return;
          }
          if (!verifyRoles('research', 0)) {
            return;
          }
          window.location.href = process.env.VUE_APP_SERVICE_CP_HOMEACTIVITYDETAIL + '\\' + id;
        break;
        case '合集':
          if (!verifyRoles('research', 0)) {
            return;
          }
          window.location.href = process.env.VUE_APP_SERVICE_CP_RESEARCHDETAIL + '\\' + id;
        break;
        default:
          break;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import './common.scss';
.search-list-product{
  .list-item{
    margin-bottom: 11px;
    display: flex;
    align-items: center;
    .tags{
      margin-right: 16px;
      ::v-deep .el-tag--medium{
        text-align: center;
      }
    }
    .name{
      cursor: pointer;
    }
  }
}
</style>
